﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ADONetTest0001
{
    class Program
    {
        static void Main(string[] args)
        {
            var conString = "server=.;database=User;uid=sa;pwd=123456";

            SqlConnection sqlConnection = new SqlConnection(conString);

            sqlConnection.Open();

            var cmdString = "select * from Student";

            SqlCommand command = new SqlCommand(cmdString, sqlConnection);

            var reader = command.ExecuteReader();

            Console.WriteLine("{0}\t{1}\t{2}","ID","学生姓名","年龄");

            while (reader.Read())
            {
                Console.WriteLine("{0}\t{1}\t{2}",reader["Id"], reader["Name"], reader["Age"]);
            }

            sqlConnection.Close();

            DataTable table = new DataTable();

            SqlDataAdapter dataAdapter = new SqlDataAdapter(cmdString, conString);

            dataAdapter.Fill(table);

            foreach(DataRow row in table.Rows)
            {
                Console.WriteLine(row["Id"]);
            }

        }
    }
}
